package com.zhdl.modules.assemblybolt;

import com.project.common.util.DelayUtil;
import com.zhdl.hardware.clamping_jaw.inspire.repository.impl.InspirePortCmdHandleDaoImpl;
import com.zhdl.hardware.clamping_jaw.micro.repository.impl.MicroPortCmdHandleDaoImpl;
import com.zhdl.hardware.plc.siemens.repository.impl.SiemensPortCmdHandleDaoImpl;
import com.zhdl.hardware.robot.kuka.repository.KukaCmdHandleDao;
import com.zhdl.modules.assemblybolt.service.AssemblyBoltService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class AssemblyBoltProcess {

    @Resource
    KukaCmdHandleDao kukaCmdHandleDao;
    @Resource
    TransportScrewNextProcess transportScrewNextProcess;
    @Resource
    private MicroPortCmdHandleDaoImpl microPortCmdHandleDao;
    @Resource
    private InspirePortCmdHandleDaoImpl inspirePortCmdHandleDao;
    @Resource
    private SiemensPortCmdHandleDaoImpl siemensPortCmdHandleDao;
    @Resource
    private AssemblyBoltService assemblyBoltService;
    /**
     * plc信号
     */
    private String siemensValue;

    /**
     * 初始化串口网口
     */
    public void initPort() {
        /*
            初始化串口/网口
         */
        microPortCmdHandleDao.addPort("3");
        inspirePortCmdHandleDao.addPort("7");
        siemensPortCmdHandleDao.addPort("192.168.1.30:502");
//        kukaCmdHandleDao.addPort("172.31.1.147:59152");
        kukaCmdHandleDao.initEvent();
        DelayUtil.delayedExecution(5000, new Runnable() {
            @Override
            public void run() {
                transportScrewNextProcess.init();
            }
        });

//        log.info("initPort>>>>>>>>>>>>>>>>>>>>>>>");
//        transportScrewNextProcess.startProcess();


        /*
            开启一直读PLC
         */
        assemblyBoltService.PlcRead0To400(s -> {
            siemensValue = s;
            log.info("plc值为" + s);
        });
    }

}
